// import { COLUMN_WIDTH } from '@/utils/service.js'
import { dateFormat } from '@/utils/date'

export const createColumns = (vm) => {
  const audit = vm.hasPermission('instruct/needAudit/list/audit')
  return [
    {
      title: '',
      width: 34,
      align: 'center',
      type: 'selection',
    },
    {
      title: '序号',
      key: 'id',
      align: 'center',
      width: 80,
      render(h, params) {
        return <div>{(vm.formData.pageNo - 1) * vm.formData.pageSize + params.index + 1}</div>
      },
    },
    {
      title: '指令编号',
      align: 'center',
      render(h, params) {
        return h(
          'router-link',
          {
            props: {
              to: { name: 'pendingReview_detailDirective', query: { f: 'detail', id: params.row.id, p: 'pend' } },
            },
          },
          params.row.ident,
        )
      },
    },
    {
      title: '下发时间',
      align: 'center',
      render(h, params) {
        return <div>{dateFormat(params.row.startTime || '', 'YYYY.MM.DD')}</div>
      },
    },
    {
      title: '指令来源',
      align: 'center',
      render(h, params) {
        return <div>{(params.row.source && params.row.source.value) || ''}</div>
      },
    },
    {
      title: '指令类型',
      align: 'center',
      render(h, params) {
        return <div>{(params.row.type && params.row.type.value) || ''}</div>
      },
    },
    {
      title: '指令状态',
      align: 'center',
      render(h, params) {
        return (
          <div class={'directive-' + params.row.state.key}>{(params.row.state && params.row.state.value) || ''}</div>
        )
      },
    },
    {
      title: '操作',
      align: 'center',
      render(h, params) {
        /* 待初审 复审 执行中可以终止
        待初审 可以进行审核 
      按钮状态
      1、待初审状态下，审核按钮可操作，终止按钮不可操作
      2、待复审状态下，审核按钮不可操作，终止按钮可操作
      3、终止状态下，审核按钮和终止按钮均置灰，不可操作  
      */
        const state = (params.row.state && params.row.state.key) || ''
        // const state = ''
        // console.log('state', state)
        // const isFirst = state === 'FIRST_AUDIT'
        // const isAbort = ['FIRST_AUDIT', 'SECOND_AUDIT', 'RUNNING'].includes(state)
        const isFirst = params.row.canFirstAudit
        const isAbort = params.row.canAbort

        let audit_btn = ''
        if (audit) {
          audit_btn = (
            <icon-button
              icon={isFirst && state === 'FIRST_AUDIT' ? 'audit_active' : 'audit'}
              title="待审核"
              activated={false}
              disabled={!isFirst || state !== 'FIRST_AUDIT'}
              nativeOnClick={() => {
                if (!isFirst) return
                vm.handleAduit(params.row)
              }}
            ></icon-button>
          )
        }
        return (
          <div>
            {audit_btn}
            <icon-button
              icon={isAbort && state === 'SECOND_AUDIT' ? 'abort_active' : 'abort'}
              title="终止"
              class={[audit_btn && 'ml14']}
              activated={false}
              disabled={!isAbort || Boolean(state !== 'SECOND_AUDIT')}
              nativeOnClick={() => {
                if (!isAbort) return
                vm.handleAbort(params.row)
              }}
            ></icon-button>
          </div>
        )
      },
    },
  ]
}

/* {
    "id": 1,
    "ident": "aed1a1465dab43a9b05458a83ce8ca6f",
    "startTime": "2024-08-21 00:00:00",
    "endTime": "2024-08-22 00:00:00",
    "source": {
        "key": "正能量稿池",
        "value": "其他"
    },
    "type": {
        "key": "ARTICLE",
        "value": "稿件转发指令"
    },
    "state": {
        "key": "FIRST_AUDIT",
        "value": "待初审"
    },
    "title": "test direcitve",
    "content": "dddddd",
    "location": "CHANNEL",
    "visible": "PUBLIC",
    "supervisoryLen": 30,
    "remark": null,
    "template": 1,
    "json": "[{\"title\":\"新建视频稿件4\",\"url\":\"wwwwwwww\"},{\"title\":\"新建视频稿件2\",\"url\":\"wwwwwwww\"}]",
    "scopeType": "SITE",
    "scopeCategory": "2",
    "targets": [
        "8",
        "1",
        "17",
        "6",
        "14",
        "12",
        "5",
        "4",
        "15",
        "13",
        "2",
        "16",
        "3",
        "7"
    ],
    "createBy": "default",
    "createTime": "2024-08-21 11:25:59",
    "attachment": {
        "key": 1,
        "value": "新建 Microsoft Word 文档.docx"
    },
    "clocation": null
} */
